/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import interfaces.InternationalizableEntity;
import interfaces.InternationalizableEntityDescription;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author damfercer
 */
@Entity
@Table(name = "language")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Language.findAll", query = "SELECT l FROM Language l"),
    @NamedQuery(name = "Language.findByIdLanguage", query = "SELECT l FROM Language l WHERE l.idLanguage = :idLanguage"),
    @NamedQuery(name = "Language.findByDescription", query = "SELECT l FROM Language l WHERE l.description = :description"),
    @NamedQuery(name = "Language.findByCode", query = "SELECT l FROM Language l WHERE l.code = :code")})
public class Language implements Serializable, Comparable<Language>,InternationalizableEntity {
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idLanguage")
    private List<CompanyAdquiredProfileFolderStateDescription> companyAdquiredProfileFolderStateDescriptionList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "language")
    private List<UserConfiguration> userConfigurationList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "language")
    private List<EducationalStatusDescription> educationalStatusDescriptionList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "language", fetch = FetchType.LAZY)
    private List<LanguageDescription> languageDescriptionList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "language", fetch = FetchType.LAZY)
    private List<WorkingStatusDescription> workingStatusDescriptionList;
    @OneToMany(mappedBy = "language", fetch = FetchType.LAZY)
    private List<SearchLanguageInfoRequerimentAndOperator> searchLanguageInfoRequerimentAndOperatorList;
    @OneToMany(mappedBy = "language", fetch = FetchType.LAZY)
    private List<SearchLanguageInfoRequerimentOrOperator> searchLanguageInfoRequerimentOrOperatorList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "language", fetch = FetchType.LAZY)
    private List<TimeAvailabilityDescription> timeAvailabilityDescriptionList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "language")
    private List<CandidateLanguageInfo> candidateLanguageInfoList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "language")
    private List<LanguageLevelDescription> languageLevelDescriptionList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "language", fetch = FetchType.LAZY)
    private List<JobDurationDescription> jobDurationDescriptionList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "language", fetch = FetchType.LAZY)
    private List<JobPositionDescription> jobPositionDescriptionList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "language", fetch = FetchType.LAZY)
    private List<CandidateTypeDescription> candidateTypeDescriptionList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "language", fetch = FetchType.LAZY)
    private List<SectorDescription> sectorDescriptionList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "language", fetch = FetchType.LAZY)
    private List<EducationalLevelDescription> educationalLevelDescriptionList;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_LANGUAGE")
    private Integer idLanguage;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 30)
    @Column(name = "DESCRIPTION")
    private String description;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 5)
    @Column(name = "CODE")
    private String code;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idLanguage", fetch = FetchType.LAZY)
    private List<CountryDescription> countryDescriptionList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idLanguage", fetch = FetchType.LAZY)
    private List<SexDescription> sexDescriptionList;

    public Language() {
    }

    public Language(Integer idLanguage) {
        this.idLanguage = idLanguage;
    }

    public Language(Integer idLanguage, String description, String code) {
        this.idLanguage = idLanguage;
        this.description = description;
        this.code = code;
    }

    public Integer getIdLanguage() {
        return idLanguage;
    }

    public void setIdLanguage(Integer idLanguage) {
        this.idLanguage = idLanguage;
    }

    @Override
    public String getDescription() {
//        String resDescription=description;
//        Locale currentLocale=FacesContext.getCurrentInstance().getViewRoot().getLocale();
//        if(!getLanguageDescriptionList().isEmpty() && !currentLocale.equals(Locale.ENGLISH)){
//            String localeCode=currentLocale.getLanguage();
//            for(LanguageDescription ld:getLanguageDescriptionList()){
//                if(ld.getCode().equals(localeCode)){
//                    resDescription=ld.getDescription();
//                }
//            }
//        }
//        return resDescription;
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @XmlTransient
    public List<CountryDescription> getCountryDescriptionList() {
        return countryDescriptionList;
    }

    public void setCountryDescriptionList(List<CountryDescription> countryDescriptionList) {
        this.countryDescriptionList = countryDescriptionList;
    }

    @XmlTransient
    public List<SexDescription> getSexDescriptionList() {
        return sexDescriptionList;
    }

    public void setSexDescriptionList(List<SexDescription> sexDescriptionList) {
        this.sexDescriptionList = sexDescriptionList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idLanguage != null ? idLanguage.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Language)) {
            return false;
        }
        Language other = (Language) object;
        if ((this.idLanguage == null && other.idLanguage != null) || (this.idLanguage != null && !this.idLanguage.equals(other.idLanguage))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entities.Language[ idLanguage=" + idLanguage + " ]";
    }

    @XmlTransient
    public List<CandidateTypeDescription> getCandidateTypeDescriptionList() {
        return candidateTypeDescriptionList;
    }

    public void setCandidateTypeDescriptionList(List<CandidateTypeDescription> candidateTypeDescriptionList) {
        this.candidateTypeDescriptionList = candidateTypeDescriptionList;
    }

    @XmlTransient
    public List<SectorDescription> getSectorDescriptionList() {
        return sectorDescriptionList;
    }

    public void setSectorDescriptionList(List<SectorDescription> sectorDescriptionList) {
        this.sectorDescriptionList = sectorDescriptionList;
    }

    @XmlTransient
    public List<EducationalLevelDescription> getEducationalLevelDescriptionList() {
        return educationalLevelDescriptionList;
    }

    public void setEducationalLevelDescriptionList(List<EducationalLevelDescription> educationalLevelDescriptionList) {
        this.educationalLevelDescriptionList = educationalLevelDescriptionList;
    }

    @XmlTransient
    public List<JobDurationDescription> getJobDurationDescriptionList() {
        return jobDurationDescriptionList;
    }

    public void setJobDurationDescriptionList(List<JobDurationDescription> jobDurationDescriptionList) {
        this.jobDurationDescriptionList = jobDurationDescriptionList;
    }

    @XmlTransient
    public List<JobPositionDescription> getJobPositionDescriptionList() {
        return jobPositionDescriptionList;
    }

    public void setJobPositionDescriptionList(List<JobPositionDescription> jobPositionDescriptionList) {
        this.jobPositionDescriptionList = jobPositionDescriptionList;
    }

    @XmlTransient
    public List<CandidateLanguageInfo> getCandidateLanguageInfoList() {
        return candidateLanguageInfoList;
    }

    public void setCandidateLanguageInfoList(List<CandidateLanguageInfo> candidateLanguageInfoList) {
        this.candidateLanguageInfoList = candidateLanguageInfoList;
    }

    @XmlTransient
    public List<LanguageLevelDescription> getLanguageLevelDescriptionList() {
        return languageLevelDescriptionList;
    }

    public void setLanguageLevelDescriptionList(List<LanguageLevelDescription> languageLevelDescriptionList) {
        this.languageLevelDescriptionList = languageLevelDescriptionList;
    }

    @XmlTransient
    public List<TimeAvailabilityDescription> getTimeAvailabilityDescriptionList() {
        return timeAvailabilityDescriptionList;
    }

    public void setTimeAvailabilityDescriptionList(List<TimeAvailabilityDescription> timeAvailabilityDescriptionList) {
        this.timeAvailabilityDescriptionList = timeAvailabilityDescriptionList;
    }

    @XmlTransient
    public List<SearchLanguageInfoRequerimentAndOperator> getSearchLanguageInfoRequerimentAndOperatorList() {
        return searchLanguageInfoRequerimentAndOperatorList;
    }

    public void setSearchLanguageInfoRequerimentAndOperatorList(List<SearchLanguageInfoRequerimentAndOperator> searchLanguageInfoRequerimentAndOperatorList) {
        this.searchLanguageInfoRequerimentAndOperatorList = searchLanguageInfoRequerimentAndOperatorList;
    }

    @XmlTransient
    public List<SearchLanguageInfoRequerimentOrOperator> getSearchLanguageInfoRequerimentOrOperatorList() {
        return searchLanguageInfoRequerimentOrOperatorList;
    }

    public void setSearchLanguageInfoRequerimentOrOperatorList(List<SearchLanguageInfoRequerimentOrOperator> searchLanguageInfoRequerimentOrOperatorList) {
        this.searchLanguageInfoRequerimentOrOperatorList = searchLanguageInfoRequerimentOrOperatorList;
    }

    @XmlTransient
    public List<WorkingStatusDescription> getWorkingStatusDescriptionList() {
        return workingStatusDescriptionList;
    }

    public void setWorkingStatusDescriptionList(List<WorkingStatusDescription> workingStatusDescriptionList) {
        this.workingStatusDescriptionList = workingStatusDescriptionList;
    }

    @XmlTransient
    public List<LanguageDescription> getLanguageDescriptionList() {
        return languageDescriptionList;
    }

    public void setLanguageDescriptionList(List<LanguageDescription> languageDescriptionList) {
        this.languageDescriptionList = languageDescriptionList;
    }

    @XmlTransient
    public List<EducationalStatusDescription> getEducationalStatusDescriptionList() {
        return educationalStatusDescriptionList;
    }

    public void setEducationalStatusDescriptionList(List<EducationalStatusDescription> educationalStatusDescriptionList) {
        this.educationalStatusDescriptionList = educationalStatusDescriptionList;
    }

    @XmlTransient
    public List<UserConfiguration> getUserConfigurationList() {
        return userConfigurationList;
    }

    public void setUserConfigurationList(List<UserConfiguration> userConfigurationList) {
        this.userConfigurationList = userConfigurationList;
    }

    @Override
    public int compareTo(Language o) {
        return this.getDescription().compareToIgnoreCase(o.getDescription());
    }

    @Override
    public Integer getId() {
        return getIdLanguage();
    }

    @Override
    public List<? extends InternationalizableEntityDescription> getDescriptionsList() {
        return getLanguageDescriptionList();
    }

    @XmlTransient
    public List<CompanyAdquiredProfileFolderStateDescription> getCompanyAdquiredProfileFolderStateDescriptionList() {
        return companyAdquiredProfileFolderStateDescriptionList;
    }

    public void setCompanyAdquiredProfileFolderStateDescriptionList(List<CompanyAdquiredProfileFolderStateDescription> companyAdquiredProfileFolderStateDescriptionList) {
        this.companyAdquiredProfileFolderStateDescriptionList = companyAdquiredProfileFolderStateDescriptionList;
    }
    
}
